#ifndef MARKERELEMENT_H
#define MARKERELEMENT_H

#include <QPointF>

enum MarkerElementType{
    JumpTo,
    MarkTo,
    Arc_To,
    JumpLaserOn,//到目标点后开指定时间的光
    PixelJumpMark,
    PixelMark,
    PixelMarkEnd,
    PowerRise,//功率上升的终点
    PowerFall,//功率下降的起点
    PowerRamp,//功率斜坡过程中的点
    PowerMark,//指定功率打印
};

class MarkerElement : public QPointF
{

public:
    MarkerElement(MarkerElementType type = JumpTo) : QPointF(), mType(type)
    {

    }

    MarkerElement(const QPointF &p, MarkerElementType  type = JumpTo)
        : QPointF(p), mType(type)
    {

    }

    MarkerElement(qreal xpos, qreal ypos, MarkerElementType  type = JumpTo)
        : QPointF(xpos, ypos), mType(type)
    {

    }

    MarkerElement(const QPointF &p, qreal angle)
        : QPointF(p), mType(Arc_To), mAngle(angle)
    {

    }

    // 重载赋值运算符
    MarkerElement& operator=(const MarkerElement &other)
    {
        if (this != &other) { // 自赋值检查
            QPointF::operator=(other); // 调用基类的赋值运算符
            mType = other.mType;
            mTime = other.mTime;
            mPixel = other.mPixel;
            mAngle = other.mAngle;
            mPowerPercent = other.mPowerPercent;
        }
        return *this;
    }

    // 重载相等性比较运算符
    bool operator==(const MarkerElement &other) const
    {
        return *this==other &&
                mType == other.mType &&
                mTime == other.mTime &&
                mPixel == other.mPixel &&
                qFuzzyCompare(mAngle, other.mAngle) && // 使用qFuzzyCompare处理浮点数比较
                qFuzzyCompare(mPowerPercent, other.mPowerPercent);
    }

    MarkerElementType type()
    {
        return mType;
    }

    void setType(MarkerElementType type)
    {
        mType = type;
    }

    int time()
    {
        return mTime;
    }

    void setTime(int ms)
    {
        mTime = ms;
    }

    uchar pixel()
    {
        return mPixel;
    }

    void setPixel(uchar pixel)
    {
        mPixel = pixel;
    }

    qreal angle()
    {
        return mAngle;
    }

    void setAngle(qreal angle)
    {
        mAngle = angle;
    }

    qreal powerPercent()
    {
        return mPowerPercent;
    }

    void setPowerPercent(qreal powerPercent)
    {
        mPowerPercent = powerPercent;
    }

    QPointF pointF()
    {
        return QPointF(x(), y());
    }

    void setPointF(QPointF p)
    {
        setX(p.x());
        setY(p.y());
    }

private:
    /**
     * @brief mType 标刻元素类型
     */
    MarkerElementType mType = JumpTo;
    /**
     * @brief mTime 开光时间,跳转后定时开光有效ms
     */
    int mTime = 0;
    /**
     * @brief mPixel 像素值,像素标刻才有用
     */
    uchar mPixel = 0;
    /**
     * @brief mAngle 弧形绘制的角度
     * 只有Arc_To有效
     */
    qreal mAngle = 0;
    /**
     * @brief mPowerPercent 缓升缓降过程中的点功率比
     */
    qreal mPowerPercent = 0;
};

Q_DECLARE_METATYPE(MarkerElementType)
Q_DECLARE_METATYPE(MarkerElement)
#endif // MARKERELEMENT_H
